home *** CD-ROM | disk | FTP | other *** search
- #include "Tools.h"
- #include "WriteCatalogFiles.h"
- #include "WriteExternalFile.h"
- #include "WriteGUIFiles.h"
- #include "WriteMainFile.h"
- #include "GenCodeCGUI.h"
- #include <libraries/mui.h>
-
- #include <ctype.h>
-
- /* Prototypes */
- #include <clib/alib_protos.h>
- #include <clib/exec_protos.h>
- #include <clib/dos_protos.h>
- #include <exec/memory.h>
-
- /* ANSI */
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
-
- /* Pragmas */
- #include <pragmas/dos_pragmas.h>
-
- /* MUIBuilder library */
- #include "MB.h"
- #include "MB_pragmas.h"
- #include "MB_protos.h"
-
- extern struct Library * DOSBase;
-
- /****************************************************************************************************************/
- /***** *****/
- /** Global variables **/
- /***** *****/
- /****************************************************************************************************************/
-
- ULONG varnb; /* number of variables */
-
- BOOL Code, Env; /* flags-options */
- BOOL Locale, Declarations;
- BOOL Notifications, Application;
- BOOL ExternalExist = FALSE;
- char *FileName, *CatalogName;/* Strings */
- char *GetString;
- char *GetMBString;
-
- FILE *file;
-
- char *HeaderFile;
- char *GUIFile;
- char *MBDir;
- char *Externals;
- char *MainFile;
- char *Catalog_h_File;
- char *Catalog_c_File;
-
- struct ObjApp *Appli;
-
- extern void end(void);
-
- void Quit(void);
-
- /****************************************************************************************************************/
- /***** *****/
- /** Init **/
- /***** *****/
- /****************************************************************************************************************/
-
- void Init(void)
- {
- HeaderFile = NULL;
- GUIFile = NULL;
- MBDir = NULL;
- Externals = NULL;
- MainFile = NULL;
- Catalog_h_File = NULL;
- Catalog_c_File = NULL;
-
- /* Get all needed variables */
- MB_Get (
- MUIB_VarNumber , &varnb,
- MUIB_Code , &Code,
- MUIB_Environment , &Env,
- MUIB_Locale , &Locale,
- MUIB_Notifications , &Notifications,
- MUIB_Declarations , &Declarations,
- MUIB_Application , &Application,
- MUIB_FileName , &FileName,
- MUIB_CatalogName , &CatalogName,
- MUIB_GetStringName , &GetString,
- TAG_END
- );
-
- if (*FileName=='\0')
- {
- DisplayMsg("Please give a name to your application in the field \"CODE\"\n");
- Quit();
- }
- if (Locale && *CatalogName=='\0')
- {
- DisplayMsg("Please give a catalog name in the field \"CATALOG\"\n");
- Quit();
- }
- if (Locale && *GetString=='\0')
- {
- DisplayMsg("Please give a \"GetString\" name in the field \"GetString\"\n");
- Quit();
- }
-
- /* Create 'GetMBString' name */
- if (strcmp(GetString, "GetMBString") == 0)
- GetMBString = "GetMBString2";
- else
- GetMBString = "GetMBString";
-
- /* Create File Names */
- remove_extend(FileName);
-
- if (!(GUIFile = AllocMemory(strlen(FileName)+6)))
- {
- Quit();
- }
- strcpy(GUIFile, FileName);
- add_extend(GUIFile, "GUI.c");
-
- if (!(HeaderFile = AllocMemory(strlen(FileName)+6)))
- {
- Quit();
- }
- strcpy(HeaderFile, FileName);
- add_extend(HeaderFile, "GUI.h");
-
- if (!(Externals = AllocMemory(strlen(FileName)+9)))
- {
- Quit();
- }
- strcpy(Externals, FileName);
- strcat(Externals, "Extern");
- add_extend(Externals, ".h");
-
- if (!(MainFile = AllocMemory(strlen(FileName)+7)))
- {
- Quit();
- }
- strcpy(MainFile, FileName);
- strcat(MainFile, "Main");
- add_extend(MainFile, ".c");
-
- if (!(Catalog_h_File = AllocMemory(strlen(FileName)+7)))
- {
- Quit();
- }
- strcpy(Catalog_h_File, FileName);
- strcat(Catalog_h_File, "_cat");
- add_extend(Catalog_h_File, ".h");
-
- if (!(Catalog_c_File = AllocMemory(strlen(FileName)+7)))
- {
- Quit();
- }
- strcpy(Catalog_c_File, FileName);
- strcat(Catalog_c_File, "_cat");
- add_extend(Catalog_c_File, ".c");
-
- /* Get Current Directory Name */
- if (!(MBDir = GetCurrentDirectory()))
- {
- Quit();
- }
- }
-
-
- /****************************************************************************************************************/
- /***** *****/
- /** FreeFileNameMemory **/
- /***** *****/
- /****************************************************************************************************************/
-
- void FreeFileNameMemory(void)
- {
- FreeMemory(HeaderFile);
- FreeMemory(GUIFile);
- FreeMemory(Externals);
- FreeMemory(MainFile);
- FreeMemory(MBDir);
- FreeMemory(Catalog_h_File);
- FreeMemory(Catalog_c_File);
- }
-
- /****************************************************************************************************************/
- /***** *****/
- /** Quit **/
- /***** *****/
- /****************************************************************************************************************/
-
- void Quit(void)
- {
- FreeFileNameMemory();
- DisposeApp(Appli);
- end();
- }
-
- /****************************************************************************************************************/
- /***** *****/
- /** PrintInfo **/
- /***** *****/
- /****************************************************************************************************************/
- void PrintInfo(char *str)
- {
- char *msg;
-
- if (!(msg = (char *)AllocMemory(9+strlen(str)+4+1)))
- Quit();
- sprintf(msg,"Generate %s ...",str);
- set(Appli->TX_Prg_Name,MUIA_Text_Contents,msg);
- FreeMemory(msg);
- }
-
- /****************************************************************************************************************/
- /***** *****/
- /** GenerateCode **/
- /***** *****/
- /****************************************************************************************************************/
-
- void GenerateCode(struct ObjApp *App,char *H_Header_Text,char *C_Header_Text,char *Main_Header_Text)
- {
- ULONG Main;
- BPTR lock;
-
- Appli = App;
-
- Init();
-
- /* test catalog description file if locale */
- if (Locale)
- {
- if (!(lock=Lock(CatalogName,ACCESS_READ)))
- {
- DisplayMsg("The catalog description file doesn't exist !!\nPlease generate it with MUIBuilder");
- Quit();
- }
- UnLock(lock);
- }
-
- if (Declarations)
- {
- PrintInfo(FilePart(HeaderFile));
- WriteHeaderFile(HeaderFile,H_Header_Text,FileName,varnb,Env,Notifications,Locale);
- }
-
- if (Env)
- {
- PrintInfo(FilePart(Externals));
- ExternalExist = WriteExternalFile(Externals,varnb);
- }
-
- PrintInfo(FilePart(GUIFile));
- WriteGUIFile(MBDir,HeaderFile,GUIFile,C_Header_Text,Externals,GetString,GetMBString,varnb,
- ExternalExist,Env,Locale,Declarations,Code,Notifications);
-
- get(App->CH_Generate_Main_File,MUIA_Selected,&Main);
- if (Main)
- {
- PrintInfo(FilePart(MainFile));
- WriteMainFile(HeaderFile,MainFile,Main_Header_Text,varnb,Locale);
- }
-
- if (Locale)
- {
- ULONG Catalog;
-
- get(App->CH_Add_new_entries_in_Catalog_Description_File,MUIA_Selected,&Catalog);
- if (Catalog)
- {
- char *command;
- FILE *file;
-
- if (!(command=AllocMemory(strlen(MBDir)+1+25+15+strlen(CatalogName)+6+strlen(GetString)+1)))
- Quit();
-
- strcpy(command,MBDir);
- AddPart(command,"WriteCatalog/WriteCatalog",strlen(MBDir)+1+25+1);
- if (!(file=fopen(command,"r")))
- {
- char *msg;
-
- if (!(msg=AllocMemory(15+strlen(command)+1)))
- {
- FreeMemory(command);
- Quit();
- }
- sprintf(msg,"Can't find %s !!\n",command);
- DisplayMsg(msg);
- FreeMemory(msg);
- }
- fclose(file);
- strcat(command," Reserved CDN \"");
- strcat(command,CatalogName);
- strcat(command,"\" GSN ");
- strcat(command,GetString);
- if (!Execute(command,NULL,NULL))
- {
- FreeMemory(command);
- Quit();
- }
-
- FreeMemory(command);
- }
-
- PrintInfo(FilePart(Catalog_h_File));
- if (!Write_Catalog_h_File(Catalog_h_File,CatalogName,GetString))
- Quit();
-
- PrintInfo(FilePart(Catalog_c_File));
- if (!Write_Catalog_c_File(Catalog_c_File,CatalogName,GetString))
- Quit();
- }
-
- set(App->TX_Prg_Name,MUIA_Text_Contents,"");
-
- FreeFileNameMemory();
- }
-